package com.xiaoyu.lanling.feature.voicematch.log

import `in`.srain.cube.util.UTUtil
import android.os.Bundle
import com.xiaoyu.lanling.util.event
import com.xiaoyu.lanling.util.logEvent
import com.xiaoyu.lanling.util.prop

object VoiceMatchLogger {

    fun click(from: String, openStatus: Boolean, isCalling: Boolean) {
        val params = Bundle()
        params.putString("from", from)
        params.putString("open_status", if (openStatus) "open" else "close")
        params.putBoolean("is_calling", isCalling)
        UTUtil.getInstance().flushEvent("voice_match_click", params)
    }

    fun exitBeforeMatch() {
        UTUtil.getInstance().logEvent("voice_match_exit_before_match")
    }

    fun requestStart() {
        UTUtil.getInstance().logEvent("voice_match_request_start")
    }

    fun exitRequestStart(waitTime: Long, reason: String) {
        val params = Bundle()
        params.putLong("wait_time", waitTime)
        params.putString("reason", reason)
        UTUtil.getInstance().logEvent("voice_match_exit_request_start", params)
    }

    fun exitRequestSuccess() {
        UTUtil.getInstance().logEvent("voice_match_exit_request_success")
    }

    fun exitRequestFailure() {
        UTUtil.getInstance().logEvent("voice_match_exit_request_failure")
    }

    fun callStart() {
        UTUtil.getInstance().logEvent("voice_match_call_start")
    }

    fun callSuccess() {
        UTUtil.getInstance().logEvent("voice_match_call_success")
    }

    fun callFailure(reason: String) {
        val params = Bundle()
        params.putString("reason", reason)
        UTUtil.getInstance().logEvent("voice_match_call_failure", params)
    }

    fun connectSuccess() {
        UTUtil.getInstance().logEvent("voice_match_call_connect_success")
    }

    fun hangup(type: String, totalTime: Long, reason: String) {
        val params = Bundle()
        params.putString("type", type)
        params.putLong("total_time", totalTime)
        params.putString("reason", reason)
        UTUtil.getInstance().logEvent("voice_match_call_hangup", params)
    }

    fun shrink() {
        UTUtil.getInstance().logEvent("voice_call_shrink")
    }

    fun disableAudio() {
        event("voice_match_disable_audio")
                .logEvent()
    }

    fun enableAudio(duration: Long) {
        event("voice_match_enable_audio")
                .prop("duration", duration)
                .logEvent()
    }

    fun evaluateDialogShow() {
        event("voice_match_evaluate_dialog_show")
                .logEvent()
    }

    fun evaluateRequestStart(evaluate: String) {
        event("voice_match_evaluate_request_start")
                .prop("evaluate", evaluate)
                .logEvent()
    }

    fun evaluateDialogCloseClick() {
        event("voice_match_evaluate_dialog_close_click")
                .logEvent()
    }
}